package com.example.demo.controller;

import com.example.demo.controller.common.Result;
import com.example.demo.entity.Image;
import com.example.demo.service.ImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.util.Map;

/**
 * @author baisongyuan
 * @className ImageController
 * @description
 * @date 2022/9/20 21:08
 */
@RestController
@RequestMapping("/image")
public class ImageController {
    @Autowired
    private ImageService imgSrv;

    @GetMapping("/num/avg")
    public Result<Map<Long, Integer>> getImageAvgByTime(
            @RequestParam("startTime") @Valid @Max(0) Long startTime,
            @RequestParam("endTime") @Valid @Min(Long.MAX_VALUE) Long endTime
    ){
        Map<Long, Integer> res = imgSrv.getImageAvgNumByTime(startTime, endTime);
        return Result.success(res);
    }
}
